#include <stdio.h>
int main()
{
    // 1.加载 ls -l 命令(程序)
    FILE *pf = popen("", "r");
    if (pf == NULL){
        printf("popen error\n");
        return -1;
    }
    else{
        printf("加载成功\n");
    }
    // 读取 ls -l  程序加载后的输出结果
    int i=0;
    while (1)
    {
        char buf[1024] = {0};
        char *ret = fgets(buf, 1024, pf);
        if (ret == NULL)
        {
            break;
        }
        printf("buf[%d]%s\n",i, buf);
        i++;
    }
    // 关闭程序
    pclose(pf);
}